﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Bovril.Rodney.Core
{
    internal static class BetfairAPIErrorProcessor
    {
        internal static void ProcessResponse(BFGlobalServiceReference.GetEventsResp response)
        {
            if (response.errorCode == BFGlobalServiceReference.GetEventsErrorEnum.API_ERROR)
            {
                throw new BetfairAPIException(response.header.errorCode.ToString());
            }
            else if (response.errorCode != BFGlobalServiceReference.GetEventsErrorEnum.OK)
            {
                throw new BetfairAPIException(response.errorCode.ToString());
            }
        }

        internal static void ProcessResponse(BFGlobalServiceReference.GetEventTypesResp response)
        {
            if (response.errorCode == BFGlobalServiceReference.GetEventsErrorEnum.API_ERROR)
            {
                throw new BetfairAPIException(response.header.errorCode.ToString());
            }
            else if (response.errorCode != BFGlobalServiceReference.GetEventsErrorEnum.OK)
            {
                throw new BetfairAPIException(response.errorCode.ToString());
            }
        }

        internal static void ProcessResponse(BFGlobalServiceReference.LoginResp response)
        {
            if (response.errorCode == BFGlobalServiceReference.LoginErrorEnum.API_ERROR)
            {
                throw new BetfairAPIException(response.header.errorCode.ToString());
            }
            else if (response.errorCode != BFGlobalServiceReference.LoginErrorEnum.OK && response.errorCode != BFGlobalServiceReference.LoginErrorEnum.OK_MESSAGES)
            {
                throw new BetfairAPIException(response.errorCode.ToString());
            }
        }

        internal static void ProcessResponse(BFGlobalServiceReference.LogoutResp response)
        {
            if (response.errorCode == BFGlobalServiceReference.LogoutErrorEnum.API_ERROR)
            {
                throw new BetfairAPIException(response.header.errorCode.ToString());
            }
            else if (response.errorCode != BFGlobalServiceReference.LogoutErrorEnum.OK)
            {
                throw new BetfairAPIException(response.errorCode.ToString());
            }
        }
    }
}
